package com.atguigu.gmall.activity.controller;

import com.atguigu.gmall.activity.service.SecKillService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillOrder;
import com.atguigu.gmall.model.activity.UserRecode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 秒杀下单controller
 */
@RestController
@RequestMapping("/seckill/order")
public class SecKillOrderController {


    @Autowired
    SecKillService secKillService;

    /**
     * 秒杀下单
     * @param skuId
     * @param time
     * @return
     */
    @GetMapping("/add")
    public Result addSecKillOrder(String skuId,String time){
        //测试数据userID,实际场景从HttpServletRequest请求头中获取
        String userId = "WangBa";
        UserRecode userRecode = secKillService.userRecode(time, userId, skuId);
        return Result.ok(userRecode);
    }

    /**
     * 查询秒杀订单
     * @param orderId
     * @return
     */
    @GetMapping(value = "/getSeckillOrder")
    public Result<List<SeckillOrder>> getSeKillOrderList(String orderId){
        //测试数据userID,实际场景从HttpServletRequest请求头中获取
        String userId = "WangBa";
        List<SeckillOrder> seKillOrderList = secKillService.getSeKillOrderList(userId, orderId);
        return Result.ok(seKillOrderList);
    }

    /**
     * 查询用户排队信息
     * @return
     */
    @GetMapping(value = "/getRecode")
    public Result<UserRecode> getUserRecode(){
        //测试数据userID,实际场景从HttpServletRequest请求头中获取
        String userId = "WangBa";
        UserRecode userRecode = secKillService.getUserRecode(userId);
        return Result.ok(userRecode);
    }
}
